"use strict";
const e = require("../../common/vendor.js"),
  t = require("../../api/request.js"),
  a = require("../../store/index.js"),
  n = {
    __name: "comments-section",
    setup(n) {
      const o = a.dataSet(),
        u = e.ref(!1),
        c = e.ref([]),
        i = e.ref(""),
        s = e.ref("");

      function r() {
        o.$patch({
          commentBox: {
            show: !1,
            _id: ""
          }
        })
      }
      async function l() {
        if ("" == s.value) return !1;
        const e = await t.requestApi("/comment_travel", {
          article_id: i.value,
          comment_content: s.value
        }, "POST");
        c.value.unshift(e.data), s.value = ""
      }
      e.watch(o.commentBox, (async e => {
        const {
          _id: a,
          show: n
        } = e;
        if (u.value = n, i.value = a, m.value = 1, n) {
          const e = await t.requestApi("/comments_data", {
            article_id: a,
            page: 1
          });
          c.value = e.data
        }
      }));
      const m = e.ref(1);
      async function v() {
        m.value++;
        const e = await t.requestApi("/comments_data", {
          article_id: i.value,
          page: m.value
        });
        c.value = [...c.value, ...e.data]
      }
      return (a, n) => e.e({
        a: e.f(c.value, ((a, n, o) => e.e({
          a: a.comment_user[0].avatarUrl,
          b: e.t(a.comment_user[0].nickname),
          c: e.t(a.content),
          d: a.isComment_user
        }, a.isComment_user ? {
          e: e.o((e => async function (e, a) {
            await t.requestApi("/comments_delete", {
              comment_id: e
            }), c.value.splice(a, 1)
          }(a._id, n)), n)
        } : {}, {
          f: n
        }))),
        b: 0 === c.value.length
      }, (c.value.length, {}), {
        c: e.o(v),
        d: e.o(l),
        e: s.value,
        f: e.o((e => s.value = e.detail.value)),
        g: e.o(l),
        h: e.o((() => {})),
        i: u.value,
        j: e.o(r)
      })
    }
  };
wx.createComponent(n);